<template>
  <div class="login-setting">
    <el-form
      ref="userForm"
      :model="userInfo"
      label-width="120px"
      style="margin-left: 120px; margin-top: 30px"
    >
      <el-form-item label="姓名:">
        <el-input v-model="userInfo.username" style="width:300px" />
      </el-form-item>

      <el-form-item label="密码:">
        <el-input v-model="userInfo.password" type="password" style="width:300px" />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="submitFn">更新</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: 'LoginSetting',
  props: {
    UserInfoList: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    return {
      // 表单
      userInfo: {
        username: '',
        password: ''
      },
      //   表单验证规则
      rules: {
        username: [{ required: true, message: '用户名不能为空', triggler: 'blur' }],
        password: [{ required: true, message: '密码不能为空', triggler: 'blur' }]
      }
    }
  },
  watch: {
    UserInfoList() {
      this.userInfo = this.UserInfoList
    //   console.log(this.UserInfoList)
    }
  },
  methods: {
    // 保存用户信息--表单验证--向父组件发送表单信息
    submitFn() {
      this.$refs.userForm.validate(valid => {
        if (!valid) return this.$message.error('请确保表单填写正确')
        this.$emit('saveUserDetailByIdDATA', this.userInfo)
      })
    }
  }
}
</script>

<style lang="scss" scoped></style>
